﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class XemThongTinBe : System.Web.UI.Page
{
    TiemPhongDataContext db = new TiemPhongDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnTimkiem_Click(object sender, EventArgs e)
    {
        var getBe = db.ThongTinBes.FirstOrDefault(b=>b.MaBe.Equals(txtMB.Text.Trim()) && b.CMT.Equals(txtCM.Text.Trim()));
        if (getBe != null)
        {
            lbHoten.Text = getBe.TenBe;
            lbMabe.Text = getBe.MaBe;
            lbNgaysinh.Text = Convert.ToDateTime(getBe.NgaySinh).ToString("d");
            lbGioitinh.Text = getBe.GioiTinh;
            lbDiachi.Text = getBe.DiaChi;
            lbChungminhthu.Text = getBe.CMT;
            messageKQ.Visible = false;
            /*select t.TenBe,v.TenVC,nvt.TenNV as 'NhanVienTiem',nvtv.TenNV as 'NhanVienTuVan',c.LieuLuong,c.Thongtintiem,c.ThoiGianTiem 
            from CHiTietTiem c 
            inner join ThongTinBe t on c.MaBe=t.MaBe 
            inner join [Vac-xin] v on c.MaVC=v.MaVC 
            inner join NhanVien nvt on c.MaNVT=nvt.MaNV 
            inner join NhanVien nvtv on c.MaNVTV=nvtv.MaNV
            where c.MaBe='MB0001' and t.CMT='134527894'*/

            var getChiTietTiem = from c in db.CHiTietTiems
                                 join t
                                   in db.ThongTinBes
                                   on c.MaBe
                                   equals t.MaBe
                                 join v
                                 in db.Vac_xins
                                 on c.MaVC
                                 equals v.MaVC
                                 join nvt
                                 in db.NhanViens
                                 on c.MaNVT
                                 equals nvt.MaNV
                                 join nvtv
                                 in db.NhanViens
                                 on c.MaNVTV
                                 equals nvtv.MaNV
                                 where c.MaBe.Equals(txtMB.Text) && t.CMT.Equals(txtCM.Text)

                                 select
                                 new
                                 {
                                     TenBe = t.TenBe,
                                     TenVC = v.TenVC,
                                     NhanVienTiem = nvt.TenNV,
                                     NhanVienTuVan = nvtv.TenNV,
                                     LieuLuong = c.LieuLuong,
                                     Thongtintiem = c.Thongtintiem,
                                     ThoiGianTiem = c.ThoiGianTiem
                                 };
            if (getChiTietTiem.ToArray()!=null)
            {
                listChiTietTiem.Visible = true;
                this.ListViewChiTietTiem.DataSource = getChiTietTiem;
                this.ListViewChiTietTiem.DataBind();
            }
            else
            {
                messageKQ.Visible = true;
                messageKQ.Text = "<font style='color:red;'>Kết quả tìm kiếm chưa có chi tiết tiêm.</font>";
                listChiTietTiem.Visible = false;
            }            
        }
        else
        {
            messageKQ.Text = "<font style='color:red;'>Kết quả không tìm thấy thông tin bé.</font>";
            messageKQ.Visible = true;
            lbHoten.Text = "";
            lbMabe.Text = "";
            lbNgaysinh.Text = "";
            lbGioitinh.Text = "";
            lbDiachi.Text = "";
            lbChungminhthu.Text = "";
            listChiTietTiem.Visible = false;
        }
    }
}